package com.sbr.seb.wicket.page;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sbr.genericdao.DAO;
import com.sbr.genericdao.jpa.JPADAO;
import com.sbr.seb.rule.entity.PersistedService;

/**
 * Homepage
 */
public class AddServicePage extends BasePage {

	private static final long serialVersionUID = 1L;
	protected static final Logger logger = LoggerFactory.getLogger(AddServicePage.class);

	@SpringBean
	private DAO<PersistedService> serviceDao;

	private List letters = Arrays.asList(new String[] { "A", "B", "C" });
	public String selected = "B";

	/**
	 * Constructor that is invoked when page is invoked without a session.
	 * 
	 * @param parameters
	 *            Page parameters
	 */
	public AddServicePage() {
		super();
//		serviceDao = new DAO<PersistedService>() {
//
//			@Override
//			public void add(PersistedService entity) {
//				// TODO Auto-generated method stub
//
//			}
//
//			@Override
//			public void delete(PersistedService entity) {
//				// TODO Auto-generated method stub
//
//			}
//
//			@Override
//			public List<PersistedService> findAll() {
//				PersistedService service = new PersistedService();
//				service.setName("Service1");
//
//
//				return Arrays.asList(service);
//			}
//
//			@Override
//			public PersistedService findById(int id) {
//				// TODO Auto-generated method stub
//				return null;
//			}
//
//			@Override
//			public PersistedService update(PersistedService entity) {
//				// TODO Auto-generated method stub
//				return null;
//			}
//
//		};

		final TextField<Object> nameText = new RequiredTextField("name", new Model());
		final DropDownChoice selectSpecificationBox = new DropDownChoice("selectSpecificationBox", new PropertyModel(this, "selected"), letters);


		Form form = new Form("addServiceForm") {
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit() {
				logger.debug("onSubmit called");
				
				PersistedService service = new PersistedService();
				service.setName(nameText.getValue());
//				serviceDao.add(service);
			}
		};
		form.add(nameText);
		form.add(selectSpecificationBox);
		add(form);
		add(new FeedbackPanel("feedbackPanel"));
	}

}
